#include<stdio.h>
long luong[400010],m,n,sp;
long max(long a,long b){
    return a>b?a:b;
}
long lech(long n){
    long a=1,i;
    for(i=n-1;i>0;i=i>>1)a<<=1;
    return a-1;
}
void set(long index,long value){
    long i=sp+index;
    luong[i]=value;
    while(i>0){
        luong[i/2]=max(luong[i],luong[i^1]);
        i>>=1;
    }
}
long get(long start,long stop){
    start+=sp;
    stop+=sp;
    long left=luong[start],right=luong[stop];
    while(start<stop){
        if(start&1==0 && luong[start]<luong[start+1])left=luong[start+1];
        if(stop&1==1 && luong[stop] < luong[stop-1])right=luong[stop-1];
        start>>=1;
        stop>>=1;
    }    
    return max(left,right);
}
void process(){
    long i,m,n,u,v;
    char c,k,enter=0;
    FILE *fpinp=fopen("QUERY.INP","r");
    FILE *fpout=fopen("QUERY.OUT","w");
    fscanf(fpinp,"%ld%ld",&n,&m);
    sp=lech(n);
    for(i=1;i<=m;i++){
        fscanf(fpinp,"%c%c%ld%ld",&k,&c,&u,&v);
        if(c=='S')set(u,v);
        else {
            if(enter)fprintf(fpout,"\n");
            if(u<v)fprintf(fpout,"%ld",get(u,v));
                else fprintf(fpout,"%ld",get(v,u));
            enter=1;
        }
    }
    fclose(fpinp);
}
int main(){
    process();
    return 0;
}

